package com.cn.hotel.servlet.back.news;

import com.alibaba.fastjson.JSONObject;
import com.cn.hotel.model.NewsModel;
import com.cn.hotel.service.INewsService;
import com.cn.hotel.service.impl.NewsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/news/newsEdit")
public class NewsEditServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        String id = req.getParameter("id");
        String newsType = req.getParameter("newsType");
        String newsTitle = req.getParameter("newsTitle");
        String publisher = req.getParameter("publisher");
        String newsContent = req.getParameter("newsContent");
        String releaseTime = req.getParameter("releaseTime");
        NewsModel newsModel = new NewsModel();
        newsModel.setId(id==null||"".equals(id)?0:Integer.parseInt(id));
        newsModel.setNewsType(newsType);
        newsModel.setNewsTitle(newsTitle);
        newsModel.setPublisher(publisher);
        newsModel.setNewsContent(newsContent);
        newsModel.setReleaseTime(releaseTime);
        INewsService iNewsService = new NewsServiceImpl();
        int count = iNewsService.newsEdit(newsModel);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("count",count);
        resp.getWriter().println(jsonObject);
    }
}
